<template>
	<view class="form">
		<u--form :model="form" labelPosition="top" labelWidth="150">
			<u-form-item class="formItem" label="" prop="name">
				<template #label>
					<view class="r-flex-between-center">
						<view class="">
							<text>*</text>
							<text>公司名称</text>
						</view>
						<u-icon name="arrow-right"></u-icon>
					</view>
				</template>
				<u--input v-model="form.name" border="none" placeholder="请填写公司名称"></u--input>
			</u-form-item>
			<u-form-item class="formItem" label="" prop="companyName">
				<template #label>
					<view class="r-flex-between-center">
						<view class="">
							<text>*</text>
							<text>公司全称</text>
						</view>
						<u-icon name="arrow-right"></u-icon>
					</view>
				</template>
				<u--input v-model="form.companyName" border="none" placeholder="请填写公司名称"></u--input>
			</u-form-item>
			<u-form-item class="formItem" label="公司logo" prop="title">
				<u-upload :fileList="state.fileList" @afterRead="afterRead($event,1)" @delete="deletePic($event,1)"
					name="6" multiple :maxCount="1" width="100" height="100">
				</u-upload>
			</u-form-item>
			<u-form-item class="formItem" label="" prop="address" @click="routerLink('jobAddress3')">
				<template #label>
					<view class="r-flex-between-center">
						<view class="">
							<text>*</text>
							<text>公司地址</text>
						</view>
						<u-icon name="arrow-right"></u-icon>
					</view>
				</template>
				<u--input v-model="form.address" border="none" disabled disabledColor="#fff" placeholder="请选择公司地址"></u--input>
			</u-form-item>
			<u-form-item class="formItem" label="" prop="compnayHead">
				<template #label>
					<view class="r-flex-between-center">
						<view class="">
							<text>*</text>
							<text>法定代表人</text>
						</view>
						<u-icon name="arrow-right"></u-icon>
					</view>
				</template>
				<u--input v-model="form.compnayHead" border="none" placeholder="请填写法定代表人"></u--input>
			</u-form-item>
			<u-form-item class="formItem" label="" prop="capital">
				<template #label>
					<view class="r-flex-between-center">
						<view class="">
							<text>*</text>
							<text>注册资金</text>
						</view>
						<u-icon name="arrow-right"></u-icon>
					</view>
				</template>
				<u--input v-model="form.capital" border="none" placeholder="请填写注册资金"></u--input>
			</u-form-item>
			<u-form-item class="formItem" label="" prop="number">
				<template #label>
					<view class="r-flex-between-center">
						<view class="">
							<text>*</text>
							<text>信用代码</text>
						</view>
						<u-icon name="arrow-right"></u-icon>
					</view>
				</template>
				<u--input v-model="form.number" border="none" placeholder="请填写信用代码"></u--input>
			</u-form-item>
			<u-form-item class="formItem" label="" prop="setTime">
				<template #label>
					<view class="r-flex-between-center">
						<view class="">
							<text>*</text>
							<text>成立时间</text>
						</view>
						<u-icon name="arrow-right"></u-icon>
					</view>
				</template>
				<u--input v-model="form.setTime" border="none" placeholder="请选择成立时间"></u--input>
			</u-form-item>
			<u-form-item class="formItem" label="" prop="isOpen">
				<template #label>
					<view class="r-flex-between-center">
						<view class="">
							<text>*</text>
							<text>经营状态</text>
						</view>
						<u-icon name="arrow-right"></u-icon>
					</view>
				</template>
				<u--input v-model="form.isOpen" border="none" placeholder="请选择经营状态"></u--input>
			</u-form-item>
			<u-form-item class="formItem " label="" prop="type" @click="routerLink('companyDesc')">
				<template #label>
					<view class="r-flex-between-center">
						<view class="">
							<text>*</text>
							<text>公司描述</text>
						</view>
						<u-icon name="arrow-right"></u-icon>
					</view>
				</template>
				<u-parse :content="form.info" v-if="form.info"></u-parse>
				<u--input v-else border="none" disabled disabledColor="#fff"
					placeholder="介绍公司"></u--input>
			</u-form-item>

		</u--form>
		<view class="gysBtn" @click="submitForm">
			保存
		</view>
		
		
		<u-action-sheet
			:show="state.showSelect"
			:actions="state.actions"
			title="请选择"
			description=""
			@close="state.showSelect = false"
			@select="SelectFun">
		</u-action-sheet>
	</view>
</template>
<script setup lang="ts">
	//发布岗位
	import { onMounted, reactive, ref } from "vue";
	import {
		validatePhoneNumber
	} from '@/utlis/common.js'
	import {
		getCurrentInstance
	} from 'vue'
	import {
		useRouter
	} from 'uni-mini-router'
	const router = useRouter()
	import {
		onShow,
		onHide,
		onLoad
	} from '@dcloudio/uni-app'
	// import form from "../../../uni_modules/uview-plus/libs/config/props/form";
	import {
		userStore
	} from '@/pinia';
	const userStoreInfo = userStore();
	const {
		proxy,
	} = getCurrentInstance()
	
	let itemId = ref('')
	let form1 = ref(null)
	let marketType = ref([])
	

	// let form = ref({
	// 	need: '45454545',
	// 	type: '',
	// 	typeId: '',
	// 	title: '',
	// 	description: '',
	// 	project: '',
	// 	zili: '',
	// 	anli: '',
	// 	fangshi: '',
	// 	human: '',
	// 	phone: '',
	// })
	let form = reactive({
		name:''
	})
	let state = reactive({
		fileList:[],
		type:'',
		showSelect:false,
		actions:[],
		educationBackgroundAction:[
			{name: '不限',val:''},
			{name: '初中及以下',val:0},
			{name: '高中（中专）',val:1},
			{name: '大学（本专科）',val:2},
			{name: '硕士及以上',val:3},
			{name: '高中（中专）',val:1},
		],
		workYearAction:[
			{name: '1年以内',val:0},
			{name: '1-3年',val:1},
			{name: '3-5年',val:2},
			{name: '5-8年',val:3},		
			{name: '8年以上',val:4},
		]
	})
	
	const showSelectBtn = (type)=>{
		state.type = type
		switch (type){
			case 'educationBackground':
				state.actions = state.educationBackgroundAction
				break;
			case 'workYear':
				state.actions = state.workYearAction
				break;
			default:
				break;
		}
		
		state.showSelect = true
	}
	const SelectFun = (e)=>{
		let type = state.type
		// switch (type){
		// 	case 'educationBackground':
		// 		form.title.value = e.val
		// 		break;
		// 	case 'workYear':
		// 		form.title.value = e.val
		// 		break
		// 	default:
		// 		break;
		// }
	}
	const typeChose = () => {
		let arr = marketType.value.map((item) => {
			return item.name
		})
		// console.log(marketType.value);
		uni.showActionSheet({
			itemList: arr,
			success: function (res) {
				form.value.type = arr[res.tapIndex]
				form.value.typeId = marketType.value[res.tapIndex].id
			},
			fail: function (res) {
				// console.log(res.errMsg);
			}
		});
	}
	const routerLink = (name)=>{
		router.push({
			name: name,
			params: {
				backUrl:'companyEdit1',
				
			}
		})
	}
	const companyId = ref('')
	const pageType = ref('')
	onLoad((options) => {
		companyId.value = options.companyId
		pageType.value = options.type || ''
		getCompanyDetail()
		// getMeiyeRecruitJob2List()
	})
	
	onMounted(() => {
	
	})
	//获取详情
	const getCompanyDetail = () => {
		proxy.$req('GET', proxy.$api.meiyeCompany2Details, {
			id:companyId.value,
		}).then((res) => {
			if(res.code === 200){
				form = res.result
				if(form.logo){
					state.fileList = [{url:form.logo}]
				}
				
				console.log(form,'form')
				
				
			}
		})
	}
	const submitForm = () => {
		
		proxy.$req('POST', proxy.$api.meiyeRecruitCompany3Edit, form).then((res) => {
			if(res.code === 200){
				uni.showToast({
					title:'修改成功'
				})
				router.push({
					name: 'companyDetails',
					params: {
						companyId:companyId.value,
						type:pageType.value
						
					}
				})
			}
		})
	}
</script>
<style lang="scss">
	.form {
		width: 686rpx;
		margin: 0 auto;

		.formItem {
			border-bottom: 1rpx solid #e7e7e7;

			.formItemArea {
				width: 100%;
			}
		}
	}

	.gysBtn {
		width: 686rpx;
		height: 100rpx;
		line-height: 100rpx;
		text-align: center;
		background: #000000;
		border-radius: 10rpx;
		color: #fff;
		margin: 50rpx auto;
	}
</style>